package com.zsxb.crm.service.impl;

import com.zsxb.crm.dto.MenuPageDTO;
import com.zsxb.crm.mapper.MenuMapper;
import com.zsxb.crm.pojo.Menu;
import com.zsxb.crm.service.MenuService;
import com.zsxb.crm.vo.MenuVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    /**
     * 菜单管理分页查询
     */
    @Override
    public List<Menu> queryAll(MenuPageDTO menuPageDTO) {
        return menuMapper.queryAll(menuPageDTO);
    }

    /**
     * 菜单栏新增
     */
    @Override
    public void insert(Menu menu) {
        // TODO   切面类实现字段自动注入
        menu.setCreateTime(LocalDateTime.now());
        menu.setUpdateTime(LocalDateTime.now());
        menuMapper.add(menu);
    }

    /**
     * 菜单栏删除
     */
    @Override
    public void delete(Long menuId) {
        menuMapper.deleteByMenuId(menuId);
    }

    /**
     * 根据id查询菜单栏详情
     */
    @Override
    public MenuVO queryByMenuId(Long menuId) {
        return  menuMapper.queryByMenuId(menuId);
    }
}
